package com.example.demo.zaqizabatest.sortalgorithm;

/**
 *
 * 先归并那些微型数组，然后成对归并得到的微型数组。
 *
 * @ClassName Down2UpMergeSort 自底向上归并排序
 * @Author lys4134
 * @Date 2021/12/29 09:51:31
 * @Description Down2UpMergeSort
 * @Version 1.0
 **/
public class Down2UpMergeBaseSort<T extends Comparable<T>> extends MergeBaseSort<T> {

    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    @Override
    public void sort(T[] nums) {

        final int N = nums.length;
        aux = (T[]) new Comparable[N];

        for (int sz = 1; sz < N; sz += sz) {
            for (int lo = 0; lo < N - sz; lo += sz + sz) {
                merge(nums, lo, lo + sz - 1, Math.min(lo + sz + sz - 1, N - 1));
            }
        }
    }
}